package com.iwhalecloud.bss.kite.cucc.web.controller.attr;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IChargeUnitService;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.ChargeUnitQryDTO;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.ChargeUnitVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.UnicomRegionTreeVO;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname ChargeUnitController
 * @Description 查询收费单位
 * @Author zhang.song
 * @Date 2022-01-21 17:25
 */
@RestController
@RequestMapping("/chargeUnit")
public class ChargeUnitController {

    @Autowired
    private IChargeUnitService chargeUnitService;

    /**
     * 收费单位查询
     * @author zhang.song
     * @date 2022-01-21 17:24
     * @param chargeUnitQryDTO
     * @return com.iwhalecloud.bss.kite.client.dto.DataResult<com.iwhalecloud.bss.kite.cucc.client.vo.attr.ChargeUnitVO>
     */
    @PostMapping("/queryChargeUnit")
    public DataResult<ChargeUnitVO> queryChargeUnit(@RequestBody(required = false) ChargeUnitQryDTO chargeUnitQryDTO) {
        if(chargeUnitQryDTO == null) {
            chargeUnitQryDTO = new ChargeUnitQryDTO();
        }

        String cityCode = ContextUtil.getLoginInfo().getUserInfo().getPostLanId();
        // 参数过滤掉操作员工号归属城市
        chargeUnitQryDTO.setExcludeEparchyCode(cityCode);

        ChargeUnitVO chargeUnitVO = chargeUnitService.queryChargeUnit(chargeUnitQryDTO);
        return ErrorConsts.SUCCESS.getResult(chargeUnitVO);
    }

    /**
     * 查询区域省市树
     * @author zhang.song
     * @date 2022-02-06 16:52
     * @return com.iwhalecloud.bss.kite.client.dto.DataResult<java.util.List<com.iwhalecloud.bss.kite.cucc.client.vo.attr.UnicomRegionTreeVO>>
     */
    @GetMapping("/getProvCityTree")
    public DataResult<List<UnicomRegionTreeVO>> getProvCityTree() {
        List<UnicomRegionTreeVO> regionTrees = chargeUnitService.getProvCityTree();
        return ErrorConsts.SUCCESS.getResult(regionTrees);
    }
}
